library(bayesrules) 
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.4     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   2.0.1     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(janitor)
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test

Exercise 4.1

plot_beta(1.8,1.8)

plot_beta(3,2)

plot_beta(1,10)

plot_beta(1,3)

plot_beta(17,2)

a. Beta(1.8,1.8) centering π on 0.5

  1. Beta(3,2) somewhat favoring π>0.5

  2. Beta(1,10) strongly favoring π<0.5

  3. Beta(1,3) somewhat favoring π<0.5

  4. Beta(17,2) strongly favoring π>0.5

Exercise 4.2

plot_beta_binomial(2, 2, 8, 11)

plot_beta_binomial(2, 2, 3, 11)

plot_beta_binomial(3, 8, 2, 6)

plot_beta_binomial(3, 8, 4, 6)

plot_beta_binomial(3, 8, 2, 4)

plot_beta_binomial(8, 3, 2, 4)

e. alpha = 3, beta = 8, y = 2, n = 4 to the plot_beta_binomial() function generated the plot.

Exercise 4.3

plot_beta(1,60)

plot_beta(1,1)

plot_beta(36,2)

plot_beta(6,4)

plot_beta(1,3)

a. Ben says that it is really unlikely. Beta(1,60)

  1. Albert says that he is quite unsure and hates trees. He has no idea. Beta(1,1)

  2. Katie gives it some thought and, based on what happened last year, thinks that there is a very high chance. Beta(36,2)

  3. Daryl thinks that there is a decent chance, but he is somewhat unsure. Beta(6,4)

  4. Scott thinks it probably won’t happen, but he’s somewhat unsure. Beta(1,3)

Exercise 4.4

Kimya thinks that the local ice cream shop is more likely to be closed than to be open at 2 p.m. It is most likely to be closed, but she’s somewhat unsure.

plot_beta(1,2)

Fernando thinks that it is really unlikely that the local ice cream shop is still open at 2 p.m.

plot_beta(0.5, 1)

Ciara thinks that the local ice cream shop probably won’t still be open at 2 p.m, but there are still chances that it is still open at 2 p.m, she is somewhat unsure.

plot_beta(3, 10)

Taylor thinks that there is a very high chance that the local ice cream shop is still open at 2 p.m.

plot_beta(2, 0.1)

Exercise 4.5

Kimya’s simulated posterior model Beta(3,5)

# Given Kimya's prior model is Beta(1,2) which indicates that the local ice cream shop is more likely to be closed than to be open at 2 p.m. The observed data that on 3 of the past 7 days, the shop was still open at 2 p.m would make Kimya a bit less certain that the local ice cream shop is likely to be closed at 2 p.m.
# generates random deviates
pi_k <- rbeta(1000,3,5)
pie_k <- tibble(pi_k)
ggplot(data = pie_k, mapping = aes(x = pi_k))+
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

pie_k |> 
summarize(mean= mean(pi_k))
## # A tibble: 1 × 1
##    mean
##   <dbl>
## 1 0.387

Fernando’s simulated posterior model Beta(2,3)

# Given Fernando's prior model is Beta(0.5,1) which indicates that the local ice cream shop is really unlikely to be open at 2 p.m. The observed data that on 3 of the past 7 days the shop was still open at 2 p.m would make Fernando less certain that the local ice cream shop is unlikely to be open at 2 p.m.
# generates random deviates
pi_f <- rbeta(1000,2,3)
pie_f <- tibble(pi_f)
ggplot(data = pie_f, mapping = aes(x = pi_f))+
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

pie_f |> 
summarize(mean= mean(pi_f))
## # A tibble: 1 × 1
##    mean
##   <dbl>
## 1 0.402

Ciara’s simulated posterior model Beta(3,7)

# Given Ciara's prior model is Beta(3,10) which indicates that the local ice cream shop probably won't still be open at 2 p.m. The observed data that on 3 of the past 7 days the shop was still open at 2 p.m would make Ciara less certain that the local ice cream shop probably won't still be open at 2 p.m.
# generates random deviates
pi_c <- rbeta(1000,3,7)
pie_c <- tibble(pi_c)
ggplot(data = pie_c, mapping = aes(x = pi_c))+
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

pie_c |> 
summarize(mean= mean(pi_c))
## # A tibble: 1 × 1
##    mean
##   <dbl>
## 1 0.299

Taylor’s simulated posterior model Beta(3,2)

# Given Taylor's prior model is Beta(2,0.1) which indicates that the local ice cream shop is very likely to be open at 2 p.m. The observed data that on 3 of the past 7 days the shop was still open at 2 p.m would make Taylor less certain that the local ice cream shop will be open at 2 p.m.
# generates random deviates
pi_t <- rbeta(1000,3,2)
pie_t <- tibble(pi_t)
ggplot(data = pie_t, mapping = aes(x = pi_t))+
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

pie_t |> 
summarize(mean= mean(pi_t))
## # A tibble: 1 × 1
##    mean
##   <dbl>
## 1 0.591

Exercise 4.6

plot_beta_binomial(1,2,3,7)

summarize_beta_binomial(1,2,3,7)
##       model alpha beta      mean  mode        var        sd
## 1     prior     1    2 0.3333333 0.000 0.05555556 0.2357023
## 2 posterior     4    6 0.4000000 0.375 0.02181818 0.1477098

Kimya’s posterior model is Beta(4,6). Kimya’s posterior mean value of π, E(π|Y=3) is 0.4.

plot_beta_binomial(0.5, 1,3,7)

summarize_beta_binomial(0.5, 1,3,7)
##       model alpha beta      mean      mode        var        sd
## 1     prior   0.5    1 0.3333333 1.0000000 0.08888889 0.2981424
## 2 posterior   3.5    5 0.4117647 0.3846154 0.02549627 0.1596755

Fernando’s posterior model is Beta(3.5,5). Fernando’s posterior mean value of π, E(π|Y=3) is 0.4117647.

plot_beta_binomial(3,10,3,7)

summarize_beta_binomial(3,10,3,7)
##       model alpha beta      mean      mode        var        sd
## 1     prior     3   10 0.2307692 0.1818182 0.01267963 0.1126039
## 2 posterior     6   14 0.3000000 0.2777778 0.01000000 0.1000000

Ciara’s posterior model is Beta(6,14). Ciara’s posterior mean value of π, E(π|Y=3) is 0.3.

plot_beta_binomial(2, 0.1,3,7)

summarize_beta_binomial(2, 0.1,3,7)
##       model alpha beta      mean      mode        var        sd
## 1     prior     2  0.1 0.9523810 1.0000000 0.01462951 0.1209525
## 2 posterior     5  4.1 0.5494505 0.5633803 0.02451036 0.1565579

Taylor’s posterior model is Beta(5,4.1). Taylor’s posterior mean value of π, E(π|Y=3) is 0.5494505.

The posterior models of π and posterior means of π are similar to the simulation results in the previous exercise.

Exercise 4.7

  1. The data has more influence on the posterior.
plot_beta_binomial(1,4,8,10)

  1. The prior has more influence on the posterior.
plot_beta_binomial(20,3,0,1)

  1. The prior has more influence on the posterior.
plot_beta_binomial(4,2,1,3)

  1. Roughly speaking, the posterior is close to an equal compromise between the data and the prior. To be exact, the data actually has more influence on the posterior.
plot_beta_binomial(3,10,10,13)

  1. The data has more influence on the posterior.
plot_beta_binomial(20,2,10,200)

Exercise 4.8

  1. prior pdf
plot_beta(1,4)

scaled likelihood function

plot_binomial_likelihood(8,10)

posterior pdf

plot_beta_binomial(1,4,8,10)

The prior pdf somewhat favors π<0.5, though it indicates that the value of π can range from [0,1]. The scaled likelihood somewhat favors π>0.5, though the data are relatively plausible for any between 0.125 and 1. The posterior pdf for π looks more like the scaled likelihood since the posterior understanding of π agrees more with the π values in the observed data. The likelihood function holds more influence over the posterior model than the prior does with relatively ample data. The posterior model still reflects the prior information to some extent, it’s just that the data has more influence on the posterior than the prior understanding does.

  1. prior pdf
plot_beta(20,3)

scaled likelihood function

plot_binomial_likelihood(0,1)

posterior pdf

plot_beta_binomial(20,3,0,1)

The prior pdf somewhat favors π>0.75, though it indicates that the value of π can reasonably range from [0.375,1]. The scaled likelihood somewhat favors π<0.75, though it indicates that the value of π can range from [0,1]. The posterior pdf for π looks more like the prior pdf since the posterior understanding of π agrees more with the π values from the prior information. The sample size is not big enough to make the data hold more influence over the posterior than the informative prior does with relatively low variability. The posterior model still reflects the observed data to some extent, it’s just that the prior has more influence on the posterior than the data.

  1. prior pdf
plot_beta(4,2)

scaled likelihood function

plot_binomial_likelihood(1,3)

posterior pdf

plot_beta_binomial(4,2,1,3)

The prior pdf somewhat favors π>0.5, though it indicates that the value of π can range from [0,1]. The scaled likelihood somewhat favors π<0.5, though it indicates that the value of π can range from [0,1]. The posterior pdf for π looks more like the prior pdf since the posterior understanding of π agrees more with the π values from the prior information. Though the prior is relatively vague with high prior variability, the sample size itself is small and thus not insistent enough to make the data hold more influence over the posterior than the prior does. The posterior model still reflects the observed data to some extent, it’s just that the prior has more influence on the posterior than the data.

  1. prior pdf
plot_beta(3,10)

scaled likelihood function

plot_binomial_likelihood(10,13)

posterior pdf

plot_beta_binomial(3,10,10,13)

The prior pdf somewhat favors π<0.5, though it indicates that the value of π can range from [0,0.875]. The scaled likelihood somewhat favors π>0.5, though it indicates that the value of π can range from [0.125,1]. The posterior pdf for π looks a bit more like the likelihood function since the posterior understanding of π agrees more with the π values from the data. The prior is relatively informative with low prior variability and the likelihood function is also relatively insistent with ample data, which makes the two hold approximate influences over the posterior. The posterior model reflects the insights gained from both the prior information and observed data, only is a bit more in sync with the likelihood function.

  1. prior pdf
plot_beta(20,2)

scaled likelihood function

plot_binomial_likelihood(10,200)

posterior pdf

plot_beta_binomial(20,2,10,200)

The prior pdf strongly favors π>0.75 and indicates that the value of π can range from [0.5,1]. The scaled likelihood indicates that the value of π is most likely to be around 0.0625 and can range from [0,1.125]. The posterior pdf for π looks more like the scaled likelihood since the posterior understanding of π agrees more with the π values in the observed data. The prior is relatively informative with low prior variability yet the sample size of the data is big enough to make the likelihood function hold more influence over the posterior than the prior information does. The posterior model still reflects the prior information to some extent, it’s just that the data has more influence on the posterior than the prior understanding does.

Exercise 4.9

  1. According to my prior, values for π are likely to range from 0.25 to 1, the most likely value for π is around 0.86.
plot_beta(7,2)

summarize_beta_binomial(7,2,19,20) 
##       model alpha beta      mean      mode         var         sd
## 1     prior     7    2 0.7777778 0.8571429 0.017283951 0.13146844
## 2 posterior    26    3 0.8965517 0.9259259 0.003091558 0.05560178
plot_beta_binomial(7,2,19,20)

Observing a survey in which 19 of 20 people prefer dogs would make me think that the most likely proportion of people who prefer dogs to cats is bigger than expected with the mean value of π increasing from 0.7777778 to 0.8965517. It would also make me feel more certain that people tend to like dogs more than cats with the variability decreasing from 0.017283951 to 0.003091558.

summarize_beta_binomial(7,2,1,20) 
##       model alpha beta      mean      mode        var        sd
## 1     prior     7    2 0.7777778 0.8571429 0.01728395 0.1314684
## 2 posterior     8   21 0.2758621 0.2592593 0.00665874 0.0816011
plot_beta_binomial(7,2,1,20)

Observing a survey in which 1 of 20 people prefer dogs would make me think that the most likely proportion of people who prefer dogs to cats is way smaller than expected with the mean value of π decreasing from 0.7777778 to 0.2758621. It would instead make me feel more certain that only a small proportion of people like dogs more than cats with the variability increasing from 0.017283951 to 0.00665874.

summarize_beta_binomial(7,2,10,20) 
##       model alpha beta      mean      mode         var         sd
## 1     prior     7    2 0.7777778 0.8571429 0.017283951 0.13146844
## 2 posterior    17   12 0.5862069 0.5925926 0.008085612 0.08992003
plot_beta_binomial(7,2,10,20)

Observing a survey in which 10 of 20 people prefer dogs would make me think that the most likely proportion of people who prefer dogs to cats is a bit smaller than expected with the mean value of π decreasing from 0.7777778 to 0.5862069. It would also make me feel less certain that a big proportion of people like dogs more than cats with the variability decreasing from 0.017283951 to 0.008085612. I would think people can probably like dogs more than cats, but I am somewhat not sure now.

Exercise 4.10

  1. Prior: Beta(0.5, 0.5), Posterior: Beta(8.5, 2.5) y=8, n=10
plot_beta_binomial(0.5, 0.5,8,10)

(b) Prior: Beta(0.5, 0.5), Posterior: Beta(3.5, 10.5) y=3, n=13

plot_beta_binomial(0.5, 0.5,3,13)

  1. Prior: Beta(10, 1), Posterior: Beta(12, 15) y=2, n=16
plot_beta_binomial(10, 1,2,16)

  1. Prior: Beta(8, 3), Posterior: Beta(15, 6) y=7, n=10
plot_beta_binomial(8, 3,7,10)

  1. Prior: Beta(2, 2), Posterior: Beta(5, 5) y=3, n=6
plot_beta_binomial(2, 2,3,6)

  1. Prior: Beta(1, 1), Posterior: Beta(30, 3) y=29, n=31
plot_beta_binomial(1, 1,29,31)

Exercise 4.11

  1. Posterior model: Beta(11,4)
plot_beta_binomial(1,1,10,13)

  1. Posterior model: Beta(1,2)
plot_beta_binomial(1,1,0,1)

  1. Posterior model: Beta(101,31)
plot_beta_binomial(1,1,100,130)

  1. Posterior model: Beta(21,101)
plot_beta_binomial(1,1,20,120)

  1. Posterior model: Beta(235,235)
plot_beta_binomial(1,1,234,468)

Exercise 4.12

  1. Posterior model: Beta(20,5)
plot_beta_binomial(10,2,10,13)

  1. Posterior model: Beta(10,3)
plot_beta_binomial(10,2,0,1)

  1. Posterior model: Beta(110,32)
plot_beta_binomial(10,2,100,130)

  1. Posterior model: Beta(30,102)
plot_beta_binomial(10,2,20,120)

  1. Posterior model: Beta(244,236)
plot_beta_binomial(10,2,234,468)

Exercise 4.15

  1. Posterior for π: Beta(3,3)

  2. Posterior for π: Beta(4,3)

  3. Posterior for π: Beta(4,4)

  4. Posterior for π: Beta(5,4)

Exercise 4.16

  1. Posterior for π: Beta(5,5)

  2. Posterior for π: Beta(6,9)

  3. Posterior for π: Beta(7,13)

  4. Posterior for π: Beta(9,16)

Exercise 4.17

plot_beta(4,3)

The employees think there is a decent chance that a user will click on the ad when shown, but they are somewhat unsure.

  1. Since π|(Y=y)∼Beta(α+y,β+n−y),α=4 β=3, π|(Y=0)∼Beta(4+0,3+1−0).

Posterior model of π for the first employee: Beta(4,4)

Since π|(Y=y)∼Beta(α+y,β+n−y),α=4 β=3, π|(Y=3)∼Beta(4+3,3+10−3).

Posterior model of π for the second employee: Beta(7,10)

Since π|(Y=y)∼Beta(α+y,β+n−y),α=4 β=3, π|(Y=20)∼Beta(4+20,3+100−20).

Posterior model of π for the third employee: Beta(24,83)

  1. Prior pdf, likelihood function, and posterior pdf of π for the first employee:
plot_beta_binomial(4,3,0,1)

Prior pdf, likelihood function, and posterior pdf of π for the second employee:

plot_beta_binomial(4,3,3,10)

Prior pdf, likelihood function, and posterior pdf of π for the third employee:

plot_beta_binomial(4,3,20,100)

  1. Posterior model of π for the first employee: Beta(4,4)
summarize_beta_binomial(4,3,0,1)
##       model alpha beta      mean mode        var        sd
## 1     prior     4    3 0.5714286  0.6 0.03061224 0.1749636
## 2 posterior     4    4 0.5000000  0.5 0.02777778 0.1666667

The posterior model of π for the first employee indicates that any value of π between 0 and 1 is plausible yet values of π around 0.5 are the most plausible. Observing the data that none of the 1 person clicked on the ad makes the first employee think that it is equally likely for a user to and not to click on the ad when shown. He/she feels more certain about the possible distribution of π values given the posterior variability 0.02777778 which is smaller than the prior variability 0.03061224.

Posterior model of π for the second employee: Beta(7,10)

summarize_beta_binomial(4,3,3,10)
##       model alpha beta      mean mode        var        sd
## 1     prior     4    3 0.5714286  0.6 0.03061224 0.1749636
## 2 posterior     7   10 0.4117647  0.4 0.01345636 0.1160016

The posterior model of π for the second employee indicates that any value of π between 0 and 0.875 is plausible yet values of π around 0.4 are the most plausible. Observing the data that 3 out of 10 people clicked on the ad makes the second employee think that a user probably will not click on the ad when shown, but he/she is somewhat unsure. One thing for sure is that it is less likely for a user to click on the ad when shown than expected before. He/she feels more certain about the possible distribution of π values given the posterior variability 0.01345636 which is smaller than the prior variability 0.03061224.

Posterior model of π for the third employee: Beta(24,83)

summarize_beta_binomial(4,3,20,100)
##       model alpha beta      mean      mode         var         sd
## 1     prior     4    3 0.5714286 0.6000000 0.030612245 0.17496355
## 2 posterior    24   83 0.2242991 0.2190476 0.001611009 0.04013738

The posterior model of π for the third employee indicates that any value of π between 0 and 0.5 is plausible yet values of π around 0.2 are the most plausible. Observing the data that 20 out of 100 people clicked on the ad makes the third employee think that a user is very unlikely to click on the ad when shown. He/she feels more certain about the possible distribution of π values given the posterior variability 0.001611009 which is smaller than the prior variability 0.03061224.

knitr::include_graphics("image/summary.png")

The three employees’ posterior models of π with their common Beta(4,3) prior model and unique data, are summarized as above (plots in part c).

In comparison, the posterior model of π for the third employee is most in sync with his/her data while the posterior model of π for the first employee is the least in sync with his/her data.

The larger the sample size, the more “insistent” the likelihood function. For example, the likelihood function reflecting the 46% click rate in the first employee’s small sample of 1 person is quite wide – his/her data are relatively plausible for any between 0 and 1. In contrast, reflecting the % click rate in a much larger sample of 100 people, the third employee’s likelihood function is narrow – his/her data are implausible for values outside the range from 0 to 50%. In turn, we see that the more insistent the likelihood, the more influence the data holds over the posterior. Comparatively, the first employee remains the least convinced/certain (with the posterior variability of 0.02777778) by the low click rate observed in her/his small sample whereas the third employee is the most convinced/certain (with the posterior variability of 0.001611009). His/her early prior optimism evolved into to a posterior understanding that is likely only between 0 and 50%.

Exercise 4.18

  1. Posterior at the end of day one: Beta(4,4)
summarize_beta_binomial(4,3,0,1)
##       model alpha beta      mean mode        var        sd
## 1     prior     4    3 0.5714286  0.6 0.03061224 0.1749636
## 2 posterior     4    4 0.5000000  0.5 0.02777778 0.1666667

Posterior at the end of day two: Beta(7,11)

summarize_beta_binomial(4,3,3,11)
##       model alpha beta      mean  mode        var        sd
## 1     prior     4    3 0.5714286 0.600 0.03061224 0.1749636
## 2 posterior     7   11 0.3888889 0.375 0.01250812 0.1118397

Posterior at the end of day three: Beta(27,91)

summarize_beta_binomial(4,3,23,111)
##       model alpha beta      mean      mode        var         sd
## 1     prior     4    3 0.5714286 0.6000000 0.03061224 0.17496355
## 2 posterior    27   91 0.2288136 0.2241379 0.00148284 0.03850766
  1. New employee’s prior:
plot_beta(4,3)

New employee’s three posteriors in sequence:

plot_beta_binomial(4,3,0,1)

plot_beta_binomial(4,3,3,11)

plot_beta_binomial(4,3,23,111)

The new employee’s understanding of π started to be similar to what the three employee shared initially: They thought there was a decent chance that a user would click on the ad when shown, but they were somewhat unsure. At the end of the first day, after observing that none of the 1 person clicked on the ad makes the three employees thought it was equally likely for a user to and not to click on the ad when shown. At the end of the second day, after observing that only 3 out of 11 people in the past two days clicked on the ad made the employees think that a user probably would not click on the ad when shown, but they were somewhat unsure. At the end of the third day, after observing that a cumulative amount of 23 out of 111 people clicked on the ad made the employees think that a user would be very unlikely to click on the ad when shown. Overall, the employees’ confidence in the chance that a user would click on the ad when shown keeps declining throughout the three days. They felt less certain that a user would click on the ad as they observed more and more data.

  1. Posterior model of π if the new employee got data from all three of the other employees all at once until the end of their third day on the job:
summarize_beta_binomial(4,3,23,111)
##       model alpha beta      mean      mode        var         sd
## 1     prior     4    3 0.5714286 0.6000000 0.03061224 0.17496355
## 2 posterior    27   91 0.2288136 0.2241379 0.00148284 0.03850766
plot_beta_binomial(4,3,23,111)

The posterior model of π if the new employee got data from all three of the other employees all at once until the end of their third day on the job is the same as the one at the end of day three if the new employee updated their posterior model of at the end of each day since the posterior Bayesian model is invariant to whether we observe the data all at once or sequentially.

Exercise 4.19

data(bechdel, package = "bayesrules")

bechdel %>% 
  filter(year == 1980) %>% 
  tabyl(binary) %>% 
  adorn_totals("row")
##  binary  n   percent
##    FAIL 10 0.7142857
##    PASS  4 0.2857143
##   Total 14 1.0000000

Posterior model of π: Beta(5,11)

summarize_beta_binomial(1,1,4,14)
##       model alpha beta   mean      mode        var        sd
## 1     prior     1    1 0.5000       NaN 0.08333333 0.2886751
## 2 posterior     5   11 0.3125 0.2857143 0.01263787 0.1124183

The posterior mean is 0.3125 and the posterior mode is 0.2857143.

bechdel %>% 
  filter(year == 1990) %>% 
  tabyl(binary) %>% 
  adorn_totals("row")
##  binary  n percent
##    FAIL  9     0.6
##    PASS  6     0.4
##   Total 15     1.0

Posterior model of π: Beta(11,20)

summarize_beta_binomial(5,11,6,15)
##       model alpha beta      mean      mode         var         sd
## 1     prior     5   11 0.3125000 0.2857143 0.012637868 0.11241827
## 2 posterior    11   20 0.3548387 0.3448276 0.007154006 0.08458136

The posterior mean is 0.3548387 and the posterior mode is 0.3448276.

bechdel %>% 
  filter(year == 2000) %>% 
  tabyl(binary) %>% 
  adorn_totals("row")
##  binary  n   percent
##    FAIL 34 0.5396825
##    PASS 29 0.4603175
##   Total 63 1.0000000

Posterior model of π: Beta(40,54)

summarize_beta_binomial(11,20,29,63)
##       model alpha beta      mean      mode         var         sd
## 1     prior    11   20 0.3548387 0.3448276 0.007154006 0.08458136
## 2 posterior    40   54 0.4255319 0.4239130 0.002573205 0.05072677

The posterior mean is 0.4255319 and the posterior mode is 0.4239130.

bechdel %>% 
  filter(year == 1980 | year == 1990 | year == 2000) %>% 
  tabyl(binary) %>% 
  adorn_totals("row")
##  binary  n  percent
##    FAIL 53 0.576087
##    PASS 39 0.423913
##   Total 92 1.000000

Posterior model of π: Beta(40,54)

summarize_beta_binomial(1,1,39,92)
##       model alpha beta      mean     mode         var         sd
## 1     prior     1    1 0.5000000      NaN 0.083333333 0.28867513
## 2 posterior    40   54 0.4255319 0.423913 0.002573205 0.05072677

The posterior mean is 0.4255319 and the posterior mode is 0.4239130.

Exercise 4.20

Bayesian and frequentist analyses are similar in that they both use the observed data to assess the hypothesis and evaluate the parameter of interest. Both of the two analyses have subjectivity embedded in them, which is inevitable but fine because the life experiences and knowledge we carry with us inform everything from what research questions we ask to what data we collect. But since bayesian and frequentist analyses differ on their interpretations of probability - the former measures the relative plausibility of an event while the latter measures the long-run relative frequency of a repeatable event - a Bayesian analysis gives voice to the prior knowledge whereas a frequentist analysis oversimplifies real-life events by analyzing the data absent a consideration of our prior contextual understanding. More specifically, a Bayesian analysis provides a formal framework that can indicate data’s consistency/inconsistency with the prior knowledge by weighing different data against different priors (their relative strengths), which also builds the posterior understanding as a balance between the prior information with observed data. With each new piece of data, the previous posterior model reflecting our understanding prior to observing this data becomes the new prior model. In contrast, the frequentist knowledge-building diagram solely consists of the current data whose conclusion tends to throw out the prior knowledge in favor of the data from the current trial. Therefore, a Bayesian analysis is more apt to sequentially update our understanding of a parameter of interest by updating a a posterior model incrementally as more data come in. We can see the evolving process of our understandings more clearly and thus name and quantify aspects of subjectivity with a Bayesian analysis.